/**
 * 组件样式
 * 定义统一的基础组件样式
 */

/* ========== 按钮组件 ========== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-2);
    padding: var(--spacing-3) var(--spacing-4);
    border-radius: var(--radius);
    font-weight: var(--font-weight-medium);
    font-size: var(--font-size-base);
    line-height: var(--line-height-none);
    text-decoration: none;
    cursor: pointer;
    transition: all var(--transition-fast) var(--ease-in-out);
    border: 1px solid transparent;
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

/* 按钮尺寸 */
.btn-sm {
    padding: var(--spacing-2) var(--spacing-3);
    font-size: var(--font-size-sm);
    height: var(--size-button-sm);
}

.btn-lg {
    padding: var(--spacing-4) var(--spacing-6);
    font-size: var(--font-size-lg);
    height: var(--size-button-lg);
}

/* 按钮状态 */
.btn:disabled {
    pointer-events: none;
    opacity: 0.5;
    cursor: not-allowed;
}

.btn:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

/* 按钮变体 */
.btn-primary {
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
    border-color: var(--color-primary);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-primary:active:not(:disabled) {
    background-color: var(--color-primary-active);
    transform: translateY(0);
}

.btn-secondary {
    background-color: transparent;
    color: var(--color-text-primary);
    border-color: var(--color-border-primary);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--color-bg-secondary);
    border-color: var(--color-border-secondary);
}

.btn-success {
    background-color: var(--color-success);
    color: var(--color-text-inverse);
    border-color: var(--color-success);
}

.btn-success:hover:not(:disabled) {
    background-color: var(--color-success-hover);
    border-color: var(--color-success-hover);
}

.btn-warning {
    background-color: var(--color-warning);
    color: var(--color-text-inverse);
    border-color: var(--color-warning);
}

.btn-warning:hover:not(:disabled) {
    background-color: var(--color-warning-hover);
    border-color: var(--color-warning-hover);
}

.btn-error {
    background-color: var(--color-error);
    color: var(--color-text-inverse);
    border-color: var(--color-error);
}

.btn-error:hover:not(:disabled) {
    background-color: var(--color-error-hover);
    border-color: var(--color-error-hover);
}

.btn-ghost {
    background-color: transparent;
    color: var(--color-text-primary);
    border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
    background-color: var(--color-bg-secondary);
}

.btn-link {
    background-color: transparent;
    color: var(--color-primary);
    border-color: transparent;
    text-decoration: underline;
}

.btn-link:hover:not(:disabled) {
    background-color: transparent;
    color: var(--color-primary-hover);
}

/* 加载状态 */
.btn-loading {
    color: transparent;
}

.btn-loading::after {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    top: 50%;
    left: 50%;
    margin-left: -8px;
    margin-top: -8px;
    border: 2px solid var(--color-text-inverse);
    border-radius: 50%;
    border-top-color: transparent;
    animation: btn-spin 0.8s linear infinite;
}

@keyframes btn-spin {
    to { transform: rotate(360deg); }
}

/* ========== 输入框组件 ========== */

.input {
    display: flex;
    align-items: center;
    width: 100%;
    padding: var(--spacing-3);
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius);
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    font-size: var(--font-size-base);
    line-height: var(--line-height-none);
    transition: all var(--transition-fast) var(--ease-in-out);
}

.input:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.input:disabled {
    background-color: var(--color-bg-disabled);
    color: var(--color-text-disabled);
    cursor: not-allowed;
}

/* 输入框尺寸 */
.input-sm {
    padding: var(--spacing-2);
    font-size: var(--font-size-sm);
    height: var(--size-input-sm);
}

.input-lg {
    padding: var(--spacing-4);
    font-size: var(--font-size-lg);
    height: var(--size-input-lg);
}

/* 输入框状态 */
.input-error {
    border-color: var(--color-error);
}

.input-error:focus {
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.1);
}

.input-success {
    border-color: var(--color-success);
}

.input-success:focus {
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.1);
}

/* 输入框组 */
.input-group {
    display: flex;
    align-items: stretch;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--color-border-primary);
}

.input-group .input {
    border: none;
    border-radius: 0;
}

.input-group .input:focus {
    box-shadow: none;
}

.input-group-text {
    display: flex;
    align-items: center;
    padding: var(--spacing-3);
    background-color: var(--color-bg-secondary);
    color: var(--color-text-secondary);
    border: none;
    font-size: var(--font-size-base);
    white-space: nowrap;
}

.input-group .btn {
    border-radius: 0;
    border: none;
}

/* ========== 卡片组件 ========== */

.card {
    background-color: var(--color-bg-primary);
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
    transition: all var(--transition-normal) var(--ease-in-out);
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    padding: var(--spacing-6);
    border-bottom: 1px solid var(--color-border-primary);
}

.card-body {
    padding: var(--spacing-6);
}

.card-footer {
    padding: var(--spacing-6);
    border-top: 1px solid var(--color-border-primary);
    background-color: var(--color-bg-secondary);
}

.card-title {
    font-size: var(--font-size-lg);
    font-weight: var(--font-weight-semibold);
    color: var(--color-text-primary);
    margin: 0;
}

.card-subtitle {
    font-size: var(--font-size-sm);
    color: var(--color-text-secondary);
    margin: var(--spacing-1) 0 0 0;
}

.card-text {
    color: var(--color-text-secondary);
    line-height: var(--line-height-relaxed);
}

/* ========== 标签组件 ========== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: var(--spacing-1) var(--spacing-3);
    border-radius: var(--radius-full);
    font-size: var(--font-size-xs);
    font-weight: var(--font-weight-medium);
    line-height: var(--line-height-none);
    white-space: nowrap;
}

/* 标签变体 */
.badge-primary {
    background-color: var(--color-primary-light);
    color: var(--color-primary);
}

.badge-success {
    background-color: var(--color-success-light);
    color: var(--color-success);
}

.badge-warning {
    background-color: var(--color-warning-light);
    color: var(--color-warning);
}

.badge-error {
    background-color: var(--color-error-light);
    color: var(--color-error);
}

.badge-info {
    background-color: var(--color-info-light);
    color: var(--color-info);
}

.badge-secondary {
    background-color: var(--color-bg-secondary);
    color: var(--color-text-secondary);
}

/* ========== 提示框组件 ========== */

.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--spacing-3);
    padding: var(--spacing-4);
    border-radius: var(--radius);
    border: 1px solid transparent;
}

.alert-icon {
    flex-shrink: 0;
    width: var(--size-icon-lg);
    height: var(--size-icon-lg);
    display: flex;
    align-items: center;
    justify-content: center;
}

.alert-content {
    flex: 1;
}

.alert-title {
    font-weight: var(--font-weight-semibold);
    margin: 0 0 var(--spacing-1) 0;
}

.alert-message {
    margin: 0;
    font-size: var(--font-size-sm);
    line-height: var(--line-height-relaxed);
}

.alert-close {
    flex-shrink: 0;
    background: none;
    border: none;
    color: inherit;
    opacity: 0.5;
    cursor: pointer;
    padding: var(--spacing-1);
    border-radius: var(--radius-sm);
    transition: opacity var(--transition-fast) var(--ease-in-out);
}

.alert-close:hover {
    opacity: 1;
}

/* 提示框变体 */
.alert-success {
    background-color: var(--color-success-light);
    border-color: var(--color-success);
    color: var(--color-success);
}

.alert-warning {
    background-color: var(--color-warning-light);
    border-color: var(--color-warning);
    color: var(--color-warning);
}

.alert-error {
    background-color: var(--color-error-light);
    border-color: var(--color-error);
    color: var(--color-error);
}

.alert-info {
    background-color: var(--color-info-light);
    border-color: var(--color-info);
    color: var(--color-info);
}

/* ========== 进度条组件 ========== */

.progress {
    width: 100%;
    height: 8px;
    background-color: var(--color-bg-secondary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background-color: var(--color-primary);
    border-radius: var(--radius-full);
    transition: width var(--transition-normal) var(--ease-in-out);
}

.progress-bar-success {
    background-color: var(--color-success);
}

.progress-bar-warning {
    background-color: var(--color-warning);
}

.progress-bar-error {
    background-color: var(--color-error);
}

.progress-bar-info {
    background-color: var(--color-info);
}

/* ========== 加载组件 ========== */

.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--color-border-primary);
    border-radius: 50%;
    border-top-color: var(--color-primary);
    animation: spin 1s linear infinite;
}

.spinner-sm {
    width: 16px;
    height: 16px;
    border-width: 1px;
}

.spinner-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* 骨架屏 */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--color-bg-secondary) 25%,
        var(--color-bg-tertiary) 50%,
        var(--color-bg-secondary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ========== 面包屑组件 ========== */

.breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
    padding: var(--spacing-4) 0;
}

.breadcrumb-item {
    display: flex;
    align-items: center;
    gap: var(--spacing-2);
}

.breadcrumb-link {
    color: var(--color-text-secondary);
    text-decoration: none;
    transition: color var(--transition-fast) var(--ease-in-out);
}

.breadcrumb-link:hover {
    color: var(--color-primary);
}

.breadcrumb-separator {
    color: var(--color-text-tertiary);
}

.breadcrumb-active {
    color: var(--color-text-primary);
    font-weight: var(--font-weight-medium);
}

/* ========== 分页组件 ========== */

.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-1);
    padding: var(--spacing-4) 0;
}

.pagination-item {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 0 var(--spacing-2);
    border: 1px solid var(--color-border-primary);
    border-radius: var(--radius);
    background-color: var(--color-bg-primary);
    color: var(--color-text-primary);
    text-decoration: none;
    font-size: var(--font-size-sm);
    transition: all var(--transition-fast) var(--ease-in-out);
}

.pagination-item:hover:not(.active):not(:disabled) {
    background-color: var(--color-bg-secondary);
    border-color: var(--color-border-secondary);
}

.pagination-item.active {
    background-color: var(--color-primary);
    color: var(--color-text-inverse);
    border-color: var(--color-primary);
}

.pagination-item:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

.pagination-ellipsis {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    color: var(--color-text-tertiary);
}

/* ========== 工具提示组件 ========== */

.tooltip {
    position: relative;
}

.tooltip::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--color-gray-800);
    color: var(--color-text-inverse);
    padding: var(--spacing-2) var(--spacing-3);
    border-radius: var(--radius);
    font-size: var(--font-size-xs);
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast) var(--ease-in-out);
    z-index: var(--z-50);
}

.tooltip::before {
    content: "";
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 4px solid transparent;
    border-top-color: var(--color-gray-800);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast) var(--ease-in-out);
}

.tooltip:hover::after,
.tooltip:hover::before {
    opacity: 1;
}

/* ========== 模态框组件 ========== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-50);
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal) var(--ease-in-out);
}

.modal.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background-color: var(--color-bg-primary);
    border-radius: var(--radius-xl);
    max-width: 90%;
    max-height: 90vh;
    overflow: hidden;
    transform: scale(0.9);
    transition: transform var(--transition-normal) var(--ease-in-out);
}

.modal.active .modal-content {
    transform: scale(1);
}

.modal-header {
    padding: var(--spacing-6);
    border-bottom: 1px solid var(--color-border-primary);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-body {
    padding: var(--spacing-6);
    overflow-y: auto;
    max-height: calc(90vh - 140px);
}

.modal-footer {
    padding: var(--spacing-6);
    border-top: 1px solid var(--color-border-primary);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: var(--spacing-3);
}

.modal-close {
    background: none;
    border: none;
    color: var(--color-text-secondary);
    cursor: pointer;
    padding: var(--spacing-2);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast) var(--ease-in-out);
}

.modal-close:hover {
    background-color: var(--color-bg-secondary);
    color: var(--color-text-primary);
}